<?php 
use yii\helpers\Html;
use app\models\Article;
use app\models\Live;
use app\models\Comment;
use app\models\Xiong;
use app\models\Comment_live;
 use yii\widgets\LinkPager;
 use yii\helpers\Url;
 ?>
<!DOCTYPE html>

<html>
<head>
    <title>评论</title>
</head>
<body >
   <!-- Page Layout here -->

   <div class="container_l" style="padding:3%;padding-top: 20px;background: #eeeeee;" >
    <!-- 第一层卡片 -->
        <div class="valign-wrapper" style="font-size: 24px;">评论 </div>
        <div style="margin-bottom: 10px"><button class="z-depth-2" style="float: right;margin-left: 5px">搜索评论</button><input type="" name="" style="float: right;height: 28px;"></div>
        <form action="<?= Url::to(['admin/del']) ?>" method="post">
      <table>
        <thead>
          <tr>
              <th>评论者</th>
              <th >评论</th>
              <th>回复至</th>
              <th>提交时间</th>
              <th>操作</th>
          </tr>
        </thead>

        <tbody>            
             <?php 
                  if($comment!=""){
                 foreach ($comment as $key => $val) {  
                       echo "<tr>";
                       // 评论者
                       echo "<td>";
                       // input-checkbox
                        echo Html::tag('input','',['type'=>'checkbox','name'=>$val->comment_id,'style'=>['position'=>'static','opacity'=>'1','pointer-events'=>'auto'],'value'=>$val->comment_id,'class'=>'input_checkbox']);
                        // article或者live的文章的name
                        // if($comment_style=="art")                       
                        //   echo Comment::getArticleNameById($val->article_id);
                        // else if($comment_style=="live")
                        //   echo Comment_live::getLiveNameById($val->live_id);
                          echo $val->comment_name;
                         echo "</td>";
                        // 文章内容
                       echo "<td>";                                             
                       $style = ['style'=>['overflow'=>'hidden','word-break'=>'keep-all','white-space'=>'nowrap','text-overflow'=>'ellipsis','width'=>'100px']];
                       echo Html::tag('div', $val->comment_content , $style);
                       echo "</td>";
                       // 文章或者live的url
                       /*
                       这个是获得文章的name，live同理
                       Comment::getArticleName($comment->comment_id)
                       href
                       */
                       echo "<td>";
                       if($comment_style=="art")  
                       {        
                      $article =Article::getArticleById($val->article_id);
                       echo Html::tag('a',$article->article_title ,['href'=>Url::to(['blog/article']).'&id='.$article->id ]);
                     }  
                      else if($comment_style=="live"){
                       $live =Live::getLiveById($val->live_id);
                       echo Html::tag('a',$live->live_title ,['href'=>Url::to(['blog/live']).'&id='.$live->id ]);   
                      }
                       echo "</td>";
                       // 时间
                       echo Html::tag('td',$val->comment_date);
                       // 操作 -删除
                       echo "<td>";
                       echo Html::tag('a', '删除',['onclick'=>'firm1(this)','id'=>$val->comment_id]);
                       echo "</td>";
                       echo "</tr>";
                 }   
                 } 
        ?>
        <!-- tr用来放置全选的按钮，取消全选的按钮和删除提交，这里根据不同的comment提交不同的fm值 -->
             <tr>
            <td><a href="#" type="" onclick="selectAll()" class="" style="">全选</a>|<a href="#" type="" onclick="selectNone()" >取消全选</a> </td>
            <td></td>
            <td></td>
            <td>
              <?php 
              if($comment_style=="art")
              echo Html::tag('input','',['name'=>'fm','value'=>'comms','style'=>['display'=>'none']]) ;
              else 
                echo  Html::tag('input','',['name'=>'fm','value'=>'comm_lives','style'=>['display'=>'none']]) ;
            ?>             
            </td>
            <td><input type="submit" name="" value="删除选中项"   style=""></td>
          </tr>                   
        </tbody>
      </table>  
        </form>
      <?= LinkPager::widget(['pagination' => $pages]); 
            ?>
       </div>    
     </div> 
    <script type="text/javascript">
   function firm1(obj) {  

        //利用对话框返回的值 （true 或者 false）  
        if (confirm("你确定删除吗？")) {   
            var id = $(obj).attr("id");
           var fm = "comment"; 
           var comment_style = "<?php echo $comment_style ?>"
            $.post("<?= Url::to(['admin/del']) ?>",{id:id,fm:fm,style: comment_style},function(result){
            alert(result);
            location.reload();
          });            
         }
        else {  
           
        }
    }  
    function selectAll()
    {
        var inputs = document.getElementsByClassName("input_checkbox");
        for(var i =0;i<inputs.length;i++)
          inputs[i].checked=true;   
    } 
      function selectNone()
    {
        var inputs = document.getElementsByClassName("input_checkbox");
        for(var i =0;i<inputs.length;i++)
                 inputs[i].checked=false;        
    }       
</script>
</body>

</html>
